﻿package com.wandian.view
{	
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.controller.LoginCommand;
	import com.wandian.data.GameData;
	import com.wandian.model.GameDataProxy;
	import com.wandian.view.components.ui.LoadingPanelImpl;
	import com.wandian.view.mediator.LoadingMediator;
	import com.wandian.view.mediator.WindowsMediator;
	import com.wandian.view.stage.StageLoading;
	
	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.*;

	/**
	 * 全局中介者
	 * @author long
	 */
	public class ApplicationMediator extends Mediator
	{
        private var _gameData:GameDataProxy;
		private var _mcLoading1:StageLoading;
		private var _mcLoading:LoadingPanelImpl;
        /**
         * 加载某个资源，显示进度条，可以写个impl
         * @default 
         */
        private var _mcLoadSingPanel:LoadingSingPanel;
		public static const NAME:String="ApplicationMediator";

		public function ApplicationMediator(_viewComponent:Object=null)
		{
			super(NAME, _viewComponent);
            this._gameData = facade.retrieveProxy(GameDataProxy.NAME) as GameDataProxy;
            this._mcLoadSingPanel = new LoadingSingPanel();
			this.initialize();
			return;
		} 

		override public function listNotificationInterests():Array
		{
			return [CLZNoticeName.APPLICATIONMEDIATOR_LOAD_SWF_COMPLETE, CLZNoticeName.LOAD_XML_COMPLETE];
//			return [CLZNoticeName.GET_USER_INFO_BYID_SUCC, CLZNoticeName.LOAD_SWF_COMPLETE, CLZNoticeName.LOAD_SINGSWF_PRO, CLZNoticeName.LOAD_SINGSWF_COMPLETE, CLZNoticeName.GET_USER_INFO_BYID_ERR];
		} 

		override public function handleNotification(notification:INotification):void
		{
			switch (notification.getName())
			{
				case CLZNoticeName.LOAD_XML_COMPLETE://CLZNoticeName.GET_USER_INFO_BYID_SUCC:
				{
                    this._gameData.initLoadSwf();
                    this._mcLoading.showGameTip();
					break;
				}
				case CLZNoticeName.GET_USER_INFO_BYID_ERR:
				{
                    this._mcLoading.showTip(GameData.tip["GET_USER_INFO_ERR"]);
					break;
				}
				case CLZNoticeName.APPLICATIONMEDIATOR_LOAD_SWF_COMPLETE:
				{
					this.texas.removeChild(this._mcLoading);
					this._mcLoading=null;
					facade.removeMediator(LoadingMediator.NAME);
					//加载完资源之后，第一个要处理的界面
					facade.registerMediator(new MainMediator(Texas.I));//游戏主界面
                    facade.registerMediator(new WindowsMediator(Texas.I));
//                    facade.registerMediator(new PropUseMediator(this.main));
					break;
				}
				case CLZNoticeName.LOAD_SINGSWF_PRO:
				{
					if (!this.texas.contains(this._mcLoadSingPanel))
					{
						this.texas.addChild(this._mcLoadSingPanel);
					}
//					this._mcLoadSingPanel.goto(notification.getBody() as int);
					break;
				}
				case CLZNoticeName.LOAD_SINGSWF_COMPLETE:
				{
					if (this.texas.contains(this._mcLoadSingPanel))
					{
						this.texas.removeChild(this._mcLoadSingPanel);
					}
					break;
				}
				default:
				{
					break;
				}
			}
			return;
		} 

		private function initialize():void
		{
			this._mcLoading= new LoadingPanelImpl();
//			this._mcLoading.x=Texas.I.stage.stageWidth / 2;
//			this._mcLoading.y=Texas.I.stage.stageHeight / 2;
			this.texas.addChild(this._mcLoading);
            facade.registerMediator(new LoadingMediator(this._mcLoading));			
			
			facade.registerCommand(CLZNoticeName.LOGINCOMMAND_ENTER_LOGIN, LoginCommand); //登录命令
			return;
		} 

		private function get texas():Texas
		{
			return viewComponent as Texas;
		} 

	}
}
